﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QUAN_LY_NGAN_HANG_CAU_HOI_TRAC_NGHIEM
{
    public partial class FrmDangNhap : Form, IDangNhap
    {
        private DangNhapPrensenter presenter;
        private TaiKhoanDAL taikhoan;

        public FrmDangNhap()
        {
            InitializeComponent();
            presenter = new DangNhapPrensenter();
            presenter.Init(this);
        }

        private void linkThoat_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Close();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            bool kt = presenter.CheckUserPas(this.txtUser.Text, this.txtPass.Text);
            if (kt == true)
            {
                QuyenDAL quyen = new QuyenDAL();
                if (presenter.TaiKhoan.Username == "admin")
                    quyen.GhiChu = "Admin";
                else
                    quyen = QuyenDAL.LayQuyen_Ma(presenter.TaiKhoan.Quyen);
                if (quyen.GhiChu == "Admin")
                {
                    this.lnkThemGV.Visible = true;
                    this.lnkTraCuu.Visible = false;
                    this.lnkCapNhatThongTin.Visible = false;
                    this.lnkTaoCauHoi.Visible = false;
                }
                else 
                {
                    this.lnkThemGV.Visible = false;
                    this.lnkTraCuu.Visible = true;
                    this.lnkCapNhatThongTin.Visible = true;
                    this.lnkTaoCauHoi.Visible = true;
                }
                grpLogin.Visible = false;
                taikhoan = presenter.TaiKhoan;
            }
            else
            {
                MessageBox.Show("Thông Tin Đăng Nhập Thất Bại", "Thông Báo", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                this.txtPass.Text = this.txtUser.Text = "";
            }
        }

        private void FrmDangNhap_Load(object sender, EventArgs e)
        {
            this.Top = 30;
            this.Left = 50;
            this.hlp.SetHelpNavigator(this, HelpNavigator.Topic);
            this.hlp.SetHelpKeyword(this, "angNhp.html");
        }

        private void lnkTaoCauHoi_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
           	FrmTaoMoiCauHoi frm = new FrmTaoMoiCauHoi(taikhoan);
            frm.ShowDialog();
        }

        private void lnkTraCuu_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FrmTraCuuCauHoi frm = new FrmTraCuuCauHoi();
            frm.ShowDialog();
        }

        private void lnkThemGV_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FrmThemMoiGiaoVien frm = new FrmThemMoiGiaoVien();
            frm.ShowDialog();
        }

        private void lnkCapNhatThongTin_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FrmThayDoiThongTinGiaoVien frm = new FrmThayDoiThongTinGiaoVien(taikhoan);
            frm.ShowDialog();
        }
    }
}
